#!/usr/bin/python
# Filename: mjc_flash_status.py

import threading
import logging
import time
import sys
from mjs_public import singleton
from mjs_db.mjs_db import MjsDB

class MjcFlashStatus(singleton.Singleton, threading.Thread):
    def run(self):
        logging.info("thread MjcFlashStatus startup")

        # second
        up_period = 3600
        while True:
            db = MjsDB()
            sql = "UPDATE server_info SET con_status = 'offline'"
            if not db.execute(sql):
                logging.error("update all server status failed, next update at after %d second" % up_period)
            else:
                logging.info("update all server status successed, next update at after %d second" % up_period)

            time.sleep(up_period)

    def startup(self):
        self.start()
        return True

    pass